import { getTransactionConfigAll } from '@/services';
import { useEffect, useState } from 'react';

const useTransactionType = () => {
  const [transactionTypes, setTransactionTypes] = useState<any>([]);
  useEffect(() => {
    getTransactionConfigAll().then((res) => {
      if (res.code === 1) {
        setTransactionTypes(res.data);
      }
    });
  }, []);

  const geTtransactionTypeValue = (key: number) => {
    let val = '';
    if (transactionTypes.length) {
      val = transactionTypes.find((item) => item.key === key)?.value;
    }
    return val;
  };
  return {
    transactionTypes,
    setTransactionTypes,
    geTtransactionTypeValue,
  };
};

export default useTransactionType;
